package com.cyq.day27.homework;

import java.util.ArrayList;
import java.util.List;

public class MovieManager {
    private ArrayList movies = new ArrayList();
    public boolean add(Movie movie){
        boolean flag = true;
        for (int i = 0; i < movies.size(); i++) {
            Movie m = (Movie) movies.get(i);
            if(m.getId() == ((Movie) movies.get(i)).getId()){
                flag = false;
                break;
            }
        }
        if(flag){
            movies.add(movie);
        }
        return flag;
    }
    public List filter(MovieFilter filter){
        List list=new ArrayList();
        for (int i = 0; i <movies.size() ; i++) {
            Movie movie=(Movie)movies.get(i);
           if (filter.accept(movie)){
                list.add(movie);
           }
        }
       return list;
    }
}
